import numpy as np
import sys
maps = {
        "Tab": "Horizontal Tabulation",
        "Enter": "Line Feed",
        "Spacebar": "Space",
        "Esc": "Escape"
}
def formater(s, charmap, desmap):
    s.replace("Keypad\s+", "").replace("Uppercase ", "")
    if s in maps.keys():
        s = maps[s]
    if s in charmap.keys():
        res = charmap[s]
    elif s in desmap.keys():
        res = desmap[s]
    else:
        res = "00"
    return res
print(sys.argv)
with open(sys.argv[1], 'r') as ipt2, open(sys.argv[2], 'r') as iptl, open(sys.argv[3], 'r') as iptu, open(sys.argv[4], 'r') as iptm:
    resl = iptl.readlines()
    resu = iptu.readlines()
    resm = iptm.readlines()
    asciires = np.array([i.strip() for i in ipt2.readlines()]).reshape((128,-1))[:,[3,5,8]]
print(asciires)
charmap = dict(zip(asciires[:,1], asciires[:,0]))
desmap = dict(zip(asciires[:,2], asciires[:,0]))

resl_w = [[]]*128
for r in resl:
      rs = r.split(" ", 1)
      if int(rs[0], 16)<127:
          resl_w[int(rs[0], 16)] =  formater(rs[1].strip(), charmap, desmap)
print(resl_w)
with open(sys.argv[5], 'w') as opt:
    for i, r in enumerate(resl_w):
        ri = r if r else "00"
        opt.write("@{:02X}".format(i) + " " + ri +"\n")
